<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>tailored_login</title>
    <style>
        body {
            margin: 0;
            font-family: "Inter", -apple-system, BlinkMacSystemFont, San Francisco, Segoe UI, Roboto, Helvetica Neue, sans-serif;
            font-size: 14px;
            font-weight: 400;
            line-height: 1.4285714;
            color: #232e3c;
            background-color: #f4f6fa;
            -webkit-text-size-adjust: 100%;
            -webkit-tap-highlight-color: transparent;
        }

        div {
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing: border-box;
            -ms-box-sizing: border-box;
            box-sizing: border-box;
        }

        .login-box {
            display: flex;
            flex-direction: column;
            justify-content: center;
        }

        .logo-box {
            margin: 0 0 50px 0;
        }

        .logo-img {
            display: block;
            width: 300px;
            margin: 0 auto;
        }

        .form-box {
            width: 440px;
            padding: 40px 60px;
            background: #ebebeb;
            margin: 0 auto;
        }

        .input-box {
            margin: 0;
        }

        .input-el {
            display: block;
            width: 100%;
            border: 0;
            line-height: 60px;
            border-radius: 8px;
            padding: 0 20px;
            font-size: 20px;
            -moz-box-sizing: border-box;
            -webkit-box-sizing: border-box;
            -o-box-sizing: border-box;
            -ms-box-sizing: border-box;
            box-sizing: border-box;
        }

        .input-el:focus-visible {
            outline: 0;
        }

        .btn {
            width: 100px;
            height: 40px;
            line-height: 40px;
            text-align: center;
            display: block;
            margin: 0 auto;
            font-size: 18px;
            border: 0;
            background-image: linear-gradient(to right, #d2ab83, #d45d5a);
            border-radius: 30px;
            color: #ffffff;
            padding: 0;
            cursor: pointer;
        }

        .btn:hover {
            background: #bc2424;
        }

        .error-tips {
            display: block;
            line-height: 30px;
            height: 40px;
            width: 100%;
            color: #bc2424;
            font-size: 14px;
        }

    </style>

</head>
<body style="height: 100vh">
<div style="height: 100%" class="login-box">
    <div class="logo-box">
        <img src="/gmm/static/imgs/logo/tonghe.png" alt="logo" class="logo-img">
    </div>
    <div class="form-box">
        <!--            <form action="" method="post" id="login-form">-->
        <form role="form" t-attf-action="/tonghe/login" method="post"
              onsubmit="this.action = '/web/login' + location.hash" id="login-form">

            <input type="hidden" name="csrf_token" value="{{request.csrf_token()}}"/>
            <div class="input-box">
                <input type="text" name="login" class="input-el" placeholder="账号" id="name"/>
            </div>
            <div class="error-tips" id="name-error"></div>
            <div class="input-box">
                <input type="password" name="password" class="input-el" placeholder="密码" id="password" autocomplete/>
            </div>
            <div class="error-tips" id="password-error"></div>
            <div class="error-tips" t-if="error">
                {{values.error}}
            </div>
            <div class="error-tips" t-if="message">
                {{values.message}}
            </div>
            <div class="btn-box">
                <input type="submit" value="登录" class="btn" id="submit-btn">
            </div>
        </form>
    </div>
</div>
</body>
<script type="text/javascript">

    const nameInput = document.getElementById('name');
    const passwordInput = document.getElementById('password');
    const nameError = document.getElementById('name-error');
    const passwordError = document.getElementById('password-error');
    const submitBtn = document.getElementById('submit-btn');
    const loginForm = document.getElementById('login-form');

    function checkForm() {
        let flag = true;
        if (!nameInput.value) {
            nameError.innerText = '请填写账号';
            flag = false;
        } else {
            nameError.innerText = '';
        }
        if (!passwordInput.value) {
            passwordError.innerText = '请填写密码';
            flag = false;
        } else {
            passwordError.innerText = '';
        }
        return flag;
    }

    nameInput.addEventListener('blur', function () {
        checkForm();
    });
    passwordInput.addEventListener('blur', function () {
        checkForm();
    });
    submitBtn.addEventListener('click', function (event) {
        event.preventDefault();
        let flag = checkForm();
        if (!flag) {
            return;
        }
        loginForm.submit();
    });


</script>
</html>
